package com.sx.pipeline.ui.map

import android.annotation.SuppressLint
import android.opengl.Visibility
import android.view.View
import android.widget.ImageView
import com.amap.api.services.core.PoiItem
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.sx.pipeline.R

/**
 * @Author: YY
 * @Date: 2022/5/6
 * @Description: 周边地址位置列表
 */
class GeocodeAdapter(data: MutableList<PoiItem>): BaseQuickAdapter<PoiItem, BaseViewHolder>
    (R.layout.item_search_location, data) {

    var clickId: Int = 0

    override fun convert(holder: BaseViewHolder, item: PoiItem) {
        holder.setText(R.id.tv_address_title, item.title)
        holder.setText(R.id.tv_distance, "${item.distance}m | ${item.snippet}")
        if (item.distance > 1000) {
            holder.setText(R.id.tv_distance, "${item.distance.div(1000)}km | ${item.snippet}")
        }

        // 单选
        if (clickId == holder.layoutPosition) {
            holder.getView<ImageView>(R.id.image_check).visibility = View.VISIBLE
        } else {
            holder.getView<ImageView>(R.id.image_check).visibility = View.INVISIBLE
        }
    }

    @SuppressLint("NotifyDataSetChanged")
    fun setSelectClickId(position: Int) {
        this.clickId = position
        notifyDataSetChanged()
    }
}